package com.sky.config;


//配置类，用于创建alioss对象

import com.sky.properties.AliOssProperties;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class OssConfiguration {
    @Autowired
    private AliOssProperties aliOssProperties;

    //使用@Bean 自动调用方法
    @Bean
    @ConditionalOnMissingBean  //当bean中没有这个对象再创建  保证整个项目只有一个阿里云对象
    public AliOssUtil aliOssUtil() {
        return new AliOssUtil(aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName());

    }
}
